package com.potato369.cryptNacos.service.impl;

import com.potato369.cryptNacos.domain.User;
import com.potato369.cryptNacos.repository.UserRepository;
import com.potato369.cryptNacos.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class UserServiceImpl implements UserService {

    private UserRepository userRepository;

    @Autowired
    public void setUserRepository(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Override
    public User save(User user) {
        return this.userRepository.save(user);
    }

    @Override
    public void delete(User user) {
        this.userRepository.delete(user);
    }

    @Override
    public User update(User user) {
        return this.userRepository.saveAndFlush(user);
    }

    @Override
    public User findOne(Long id) {
        Optional<User> optional = this.userRepository.findById(id);
        return optional.orElse(null);
    }

    @Override
    public List<User> findAll() {
        return this.userRepository.findAll();
    }
}
